/**
 * 评估管理初始化
 */
var CdcEvaluation = {
    id: "CdcEvaluationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CdcEvaluation.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '就诊记录', field: 'episodeId', align: 'center', valign: 'middle', sortable: true},
        {title: '代码', field: 'code', align: 'center', valign: 'middle', sortable: true},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true},
        {title: '结果', field: 'result', align: 'center', valign: 'middle', sortable: true},
        {title: '评估日期', field: 'evalDate', align: 'center', valign: 'middle', sortable: true},
        {title: '业务数据类型', field: 'dataId', align: 'center', valign: 'middle', sortable: true},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true},
        {title: '操作', field: 'id', align: 'center', width: '120px', valign: 'middle',formatter:function(value,row,index){
    		var _html = '<a href="javascript:CdcEvaluation.edit(\''+row.id+'\')" title="修改"><i class="hisui-icon icon-write-order"></i></a>';
    		_html += '<a href="javascript:CdcEvaluation.del(\''+row.id+'\',\''+row.name+'\')" title="删除"><i class="hisui-icon icon-cancel"></i></a>';
    		return _html;
        }}];
};

/**
 * 检查是否选中
 */
CdcEvaluation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcEvaluation.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增评估
 */
CdcEvaluation.add = function () {
    var index = Sys.open('新增评估',Sys.backendPath + '/cdc/cdcevaluation/to_add',['800px', '420px']);
    this.layerIndex = index;
};

/**
 * 打开查看评估详情
 */
CdcEvaluation.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('评估详情',Sys.backendPath + '/cdc/cdcevaluation/to_update/' + id,['800px', '420px']);
        this.layerIndex = index;
    }
};

/**
 * 删除评估
 */
CdcEvaluation.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcevaluation/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcEvaluation.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcEvaluationId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除评估?",operation);
    }
};

/**
 * 查询评估列表
 */
CdcEvaluation.search = function () {
    var queryData = {};
    queryData['code'] = $("#code").val();
    queryData['description'] = $("#description").val();
    queryData['result'] = $("#result").val();
    queryData['evalDate'] = $("#evalDate").val();
    queryData['dataId'] = $("#dataId").val();
    queryData['isActive'] = $("#isActive").val();
    CdcEvaluation.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = CdcEvaluation.initColumn();
    var table = new BSTable(CdcEvaluation.id, Sys.backendPath + "/cdc/cdcevaluation/list", defaultColunms);
    table.setPaginationType("server");
    CdcEvaluation.table = table.init();
});
